using System;
using System.Collections.Generic;
using System.Text;
using Entities;
namespace DAL
{
   public class ShoppingCart
    {
        public List<Item> ItemCollection = new List<Item>();
        public void Add(Item item)
        {
            for (int i = 0; i < ItemCollection.Count; i++)
            {
            if (item.id == ItemCollection[i].id)
            {
                ItemCollection[i].Soluong += item.Soluong;
                return;
            }
            }
        ItemCollection.Add(item);
        }
        public void Delete(Item item)
        {
            for (int i = 0; i < ItemCollection.Count; i++)
            {
            if (item.id == ItemCollection[i].id)
            {
            ItemCollection.RemoveAt(i);
            return;
            }
            }
        }
        public void Update(Item item)
        {
            if (item.Soluong <= 0)
            {
                Delete(item);
                return;
            }
            for (int i = 0; i < ItemCollection.Count; i++)
            {
            if (item.id == ItemCollection[i].id)
            {
             ItemCollection[i].Soluong = item.Soluong;
             return;
            }
            }
        }
        public Double Total()
        {
        double total = 0;
        for (int i = 0; i < ItemCollection.Count; i++)
        {
            total += ItemCollection[i].Giaban;
        }
        return total;
        }


        public void Delete()
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }

}
